package com.travel.modules.asset.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.travel.commons.utils.Constant;
import com.travel.commons.utils.R;
import com.travel.modules.asset.entity.*;
import com.travel.modules.asset.service.*;
import com.travel.modules.sys.dto.UserDTO;
import com.travel.modules.sys.entity.SysUser;
import com.travel.modules.sys.service.SysUserService;
import org.apache.commons.lang.StringUtils;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/static/search")
public class SearchController {
    @Resource
    private ScenicAreaService scenicAreaService;

    @Resource
    private SysUserService sysUserService;

    @Resource
    private HotelService hotelService;

    @Resource
    private RouteService routeService;

    @Resource
    private StrategyService strategyService;

    @Resource
    private GoodsService goodsService;

    /**
     * 全局搜索
     * @param params keyword - 关键词
     * @return 全局结果集
     */
    @RequestMapping("/global")
    public R global(@RequestBody Map<String, Object> params) {
        String keyword = (String) params.get("keyword");
        if (StringUtils.isBlank(keyword)) {
            return R.error("缺少关键词");
        }
        String[] keywords = keyword.split(" ");
        /* 景点查询 */
        List<ScenicArea> scenicAreas = scenicAreaService.ftQueryAreas(keywords);
        /* 用户查询 */
        List<UserDTO> users = sysUserService.ftQueryUsers(keywords);
        /* 酒店查询 */
        List<Hotel> hotels = hotelService.ftQueryHotels(keywords);
        /* 路线查询 */
        List<Route> routes = routeService.ftQueryGoods(keywords);
        /* 攻略查询 */
        List<Strategy> strategies = strategyService.ftQueryStrategies(keywords);

        return R.ok().put("scenic", scenicAreas)
                     .put("user", users)
                     .put("hotel", hotels)
                     .put("goods", routes)
                     .put("strategy", strategies);
    }
}
